package com.cxx.service.impl;

import com.cxx.dao.EmployeeDao;
import com.cxx.dao.impl.EmployeeDaoImpl;
import com.cxx.entity.Employee;
import com.cxx.service.EmployeeService;

import java.util.Date;
import java.util.List;

public class EmployeeServiceImpl implements EmployeeService {
    private EmployeeDao empDao = new EmployeeDaoImpl();
    public int add(Employee emp){
        return this.empDao.save(emp);
    }

    @Override
    public List<Employee> findEmpByType(int i) {
        return this.empDao.findByType(i);
    }

    @Override
    public List<Employee> findAll() {
        return this.empDao.findAll();
    }

    @Override
    public List<Employee> findEmp(String empId, int deptno, int onDuty, Date hireDate) {

        return this.empDao.find(empId, deptno, onDuty, hireDate);
    }

    @Override
    public void delete(String empId) {
        this.empDao.delete(empId);
    }

    @Override
    public Employee findById(String empId) {
        return this.empDao.findById(empId);
    }

    @Override
    public int update(Employee emp) {
        return this.empDao.update(emp);
    }

    @Override
    public Employee login(String empId, String password) {

        Employee emp = this.empDao.findById(empId);
        if(emp == null){//用户名是错误的
            return null;
        }else{
            if(password!=null & password.equals(emp.getPassword())){
                return emp;
            }else{//用户名正确，密码错误
                return null;
            }
        }

    }
}
